package com.frxuexi.park2209.patrol

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.SPUtils
import com.frxuexi.base.entity.PatrolBean
import com.frxuexi.base.mvvm.BaseActivity
import com.frxuexi.base.net.Const
import com.frxuexi.park2209.R
import com.frxuexi.park2209.adapter.PatrolAdapter
import com.frxuexi.park2209.databinding.ActivityPatrolBinding
import com.google.gson.Gson
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class PatrolActivity : BaseActivity<ActivityPatrolBinding,PatrolViewModel>() {
    val patrolAdapter by lazy { PatrolAdapter() }
    override fun initData() {
        vm.patrolsSuc.observe(this){
            val patrolBean = Gson().fromJson(it, PatrolBean::class.java)
            Log.i("===",patrolBean.toString())
            patrolAdapter.addData(patrolBean)
            patrolAdapter.notifyDataSetChanged()
        }
    }

    override fun initView() {
        binding.rvPatrol.apply {
            adapter=PatrolAdapter()
            layoutManager=LinearLayoutManager(this@PatrolActivity)
        }

        binding.patrolHead.headerTitle.text="巡更管理"
        binding.patrolHead.headerAdd.apply {
            visibility=View.VISIBLE
            setOnClickListener {
                startActivity(Intent(this@PatrolActivity,AddPatrolActivity::class.java))
            }
        }
        binding.patrolHead.ivBack.setOnClickListener {
            finish()
        }
    }

    override fun onResume() {
        super.onResume()
        vm.selALLPatroles()
//        vm.selMyPatroles(mapOf("pUserId" to SPUtils.getInstance().getInt(Const.UID)))
    }

}